//
//  JPButton.m
//  TaskRabbit
//
//  Created by ShiXiong on 14-7-4.
//  Copyright (c) 2014年 junepartner. All rights reserved.
//

#import "JPButton.h"

@implementation JPButton

- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    NSString *title = [self titleForState:UIControlStateNormal];
    CGSize titleSize = [title sizeWithFont:[UIFont systemFontOfSize:16.0f]];
    CGSize imageSize = [[self imageForState:UIControlStateNormal] size];
        
    CGFloat x = (contentRect.size.width - imageSize.height - titleSize.width) / 2;
    CGFloat y = (contentRect.size.height - titleSize.height) / 2;
    
    return CGRectMake(x-20, y, contentRect.size.width - 20, titleSize.height);
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    NSString *title = [self titleForState:UIControlStateNormal];
    CGSize titleSize = [title sizeWithFont:[UIFont systemFontOfSize:14.0f]];
    CGSize imageSize = [[self imageForState:UIControlStateNormal] size];
    
    CGFloat x = (contentRect.size.width - imageSize.height + titleSize.width) / 2;
    CGFloat y = (contentRect.size.height - imageSize.height) / 2;
    
    return CGRectMake(x-20, y + 2, imageSize.width/2, imageSize.height/2);
}

//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    [super touchesBegan:touches withEvent:event];
//    
//    UIColor *color = [self.titleLabel.textColor colorWithAlphaComponent:0.5];
//    [self setTitleColor:color forState:UIControlStateNormal];
//    self.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.5];
//}

//- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    [super touchesMoved:touches withEvent:event];
//    
//    UITouch *touch = [touches anyObject];
//    CGPoint point = [touch locationInView:self];
//    if (CGRectContainsPoint(self.frame, point)) {
//        UIColor *color = [self.titleLabel.textColor colorWithAlphaComponent:0.5];
//        [self setTitleColor:color forState:UIControlStateNormal];
//        self.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.5];
//    } else {
//        UIColor *color = [self.titleLabel.textColor colorWithAlphaComponent:1];
//        [self setTitleColor:color forState:UIControlStateNormal];
//        self.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
//    }
//}
//
//- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    [super touchesEnded:touches withEvent:event];
//    
//    UIColor *color = [self.titleLabel.textColor colorWithAlphaComponent:1];
//    [self setTitleColor:color forState:UIControlStateNormal];
//    self.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
//}
//
//- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    [super touchesCancelled:touches withEvent:event];
//    
//    UIColor *color = [self.titleLabel.textColor colorWithAlphaComponent:1];
//    [self setTitleColor:color forState:UIControlStateNormal];
//    self.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
//}

@end
